<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表渲染</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">

        <!--遍历数组是用的最多的-->
        <h2>列表</h2>
        <button @click.once="add">添加一个项目</button>
        <ul>
            <li v-for="(per,index) in person" :key="per.id">
                {{per.name}}-{{per.age}}
            </li>
        </ul>
    </div>
</body>

<script>
    new Vue({
        el:'#root',
        data:{
          person:[
            {id:'001',name:'A',age:18},
            {id:'002',name:'B',age:19},
            {id:'003',name:'C',age:20}
          ],
        },
        methods:{
            add(){
                const p={id:'004',name:'D',age:21}
                this.person.unshift(p)
            }
        }
    })
</script>

</html>